package view
{
	import data.Globals;
	
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.text.TextFormat;
	
	import interfaces.IGameView;
	
	import view.other.ScoreView;

	public class GameView extends Sprite implements IGameView
	{
		private var gradMap:GradMap;
		
		private var monsterView:MonsterView;
		
		private var tankView:TankView;
		
		private var bulletView:BulletView;
		
		private var goodMenuView:GoodMenuView;
		
		private var animationView:AnimationView;
		
		private var mouseTipView:MouseTipView;
		
		private var captionView:CaptionView;
		
		private var alert:AlertView;
		
		public function GameView()
		{
			initFace();	
			Globals.gameView = this;
		}
		
		private function initFace():void
		{
			gradMap = new GradMap();
			this.addChild(gradMap);
			gradMap.alpha = 0.5;
			
			monsterView = new MonsterView();
			this.addChild(monsterView);
			
			tankView = new TankView();
			this.addChild(tankView);
			
			bulletView = new BulletView();
			this.addChild(bulletView);
			
			goodMenuView = new GoodMenuView();
			this.addChild(goodMenuView);
			
			animationView = new AnimationView();
			this.addChild(animationView);
			
			mouseTipView = new MouseTipView();
			
			captionView = new CaptionView();

			alert = new AlertView();
		}		
		
		public function playAnimation(type:String,back:Function=null):void{
			if(type == AnimationView.COUNT_DOWN){
				resetView();
				goodMenuView.initface();
				goodMenuView.show();
			}
			animationView.playClip(type,back);
		}
		
		public function start():void
		{
			monsterView.initMonster();
		}
		
		public function produceTank(type:String,p:Point):void{
			tankView.productionTank(type,p);
			mouseTipView.hide();
		}
		
		public function getMonsterAry():Array{
			return monsterView.aMonster;
		}
		
		public function getTankAry():Array{
			return tankView.tankAry;
		}
		
		/**
		 *发射子弹 type 子弹类型 p:Point 子弹坐标
		 */
		public function shoutBullet(type:String,p:Point,tar:Point):void{
			bulletView.createBullet(type,p,tar);
		}
		
		public function resetView():void{
			gradMap.drawLine();
			monsterView.clearView();
			tankView.clearView();
			bulletView.clearView();
			goodMenuView.clearView();
			animationView.clearView();
		}
		
		public function getCurArmType():String{
			return mouseTipView._type;
		}
		
		public function showAlert(txt:String,alertCallback:Function,yes:Boolean,no:Boolean,format:TextFormat = null):void{
			alert.setTxt(txt,format);
			alert.show(alertCallback,yes,no);
			this.addChild(alert);
		}
	     
		public function showCaption(str:String,callback:Function,tfmat:TextFormat=null):void{
			captionView.show(str,callback,tfmat);
			this.addChild(captionView);
		}
		
		public function showMouseTip(type:String):void{
			mouseTipView.show(type);
			this.addChild(mouseTipView);
		}
		
		public function calculateScore(value:int):void{
			goodMenuView.calculateScore(value);
		}
		
	}
}